/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * insumos_entradas_detalle.java
 *
 * Created on 15/06/2011, 07:41:48 PM
 */

package sie_invdis;

import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Calendar;
import java.text.*;
import java.text.ParseException;

/**
 *
 * @author Michelle
 */
public class insumos_entradas_detalle extends javax.swing.JDialog {

    private javax.swing.table.DefaultTableModel jtable_modelo;
    private JTable jtable_tiendas;

    private int buscamp=1;


    private int control_enter=0,controlcombo=0;
    private SimpleDateFormat formateador = new SimpleDateFormat("dd-MM-yyyy");
    private SimpleDateFormat formateadoresta = new SimpleDateFormat("yyyy-MM-dd");
    //se crea intancia de la clase conexion
       bd_conexion x = new bd_conexion() ;
       //se creaa la variable resultset
       ResultSet rs = null;

    /** Creates new form insumos_entradas_detalle */
    public insumos_entradas_detalle(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

public insumos_entradas_detalle(java.awt.Frame parent, boolean modal,String folio) {
        super(parent, modal);
        this.iniciar_modelo_de_tabla();
        initComponents();
        this.jbtn_guardar.setVisible(false);
        this.carga_datos(1, folio);
        this.cargar_datos_detalle(folio);

        jtb_insumos.getColumnModel().getColumn(0).setPreferredWidth(60);//status
        jtb_insumos.getColumnModel().getColumn(1).setPreferredWidth(160);//Folio
        jtb_insumos.getColumnModel().getColumn(2).setPreferredWidth(30);//status
        jtb_insumos.getColumnModel().getColumn(3).setPreferredWidth(40);//doc ant.
        jtb_insumos.getColumnModel().getColumn(4).setPreferredWidth(40);//fecha
        jtb_insumos.getColumnModel().getColumn(5).setPreferredWidth(40);//fecha llega tienda
        jtb_insumos.getColumnModel().getColumn(6).setPreferredWidth(100);//f.recepcion

    }
private void iniciar_modelo_de_tabla()
    {
        jtable_modelo=new javax.swing.table.DefaultTableModel();//Creo el modelo
        jtable_modelo.addColumn("<html><b>Clave</b></html>");
        jtable_modelo.addColumn("<html><b>Descripcion</b></html>");
        jtable_modelo.addColumn("<html><b>Unidad</b></html>");
        jtable_modelo.addColumn("<html><b>Cantidad</b></html>");
        jtable_modelo.addColumn("<html><b>Costo</b></html>");
        jtable_modelo.addColumn("<html><b>Importe</b></html>");
        jtable_modelo.addColumn("<html><b>Precio</b></html>");
        jtable_modelo.addColumn("<html><b>Tipo</b></html>");
    }

private void cargar_datos_detalle(String docto)
{
       DecimalFormat miformat = new DecimalFormat("############.###");
       float subtotal=0,impuesto=0;
       try
         {
          rs = x.sieuno_executediversosv2("select * from x1distribucion_insumos_entradas_detalle('"+docto+"') as (idreg integer,iddocto character varying(12),idarti character varying(16),can_articuloent numeric,factor numeric,cant_articulosal numeric,costoent numeric,costosal numeric,importe numeric,obserparti character varying(60),artidescrip character varying(80),unidadsal character varying(3),descriptipo character varying(40),precio1 numeric,valor_x_insumo character varying(20),unidadentrada character varying(3),itemprovee character varying(16));",variables_global.getconexiongral());
            while (rs.next())
                {
                    jtable_modelo.addRow(new Object[]{rs.getString ("idarti"),rs.getString ("artidescrip"),rs.getString("unidadsal"),rs.getString("cant_articulosal"),miformat.format(rs.getFloat("costosal")),miformat.format(rs.getFloat("Importe")),miformat.format(rs.getFloat("precio1")),rs.getString("descriptipo")});
                    subtotal+=rs.getFloat("Importe");
                }
        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }
       impuesto=subtotal*(Float.valueOf(this.jtf_impuesto.getText().toString())/100);
       this.jtf_subtotal.setText(miformat.format(subtotal));
       this.jtf_impuestoimporte.setText(miformat.format(impuesto));
       this.jtf_total.setText(miformat.format(subtotal+impuesto));
}

private void carga_datos(int opbus,String tbusca)
{
        String fechacat = "",fechallegatienda="",fechaentrega="";
        DecimalFormat miformat = new DecimalFormat("###,###,###,###");
       //invoco al metodo que trae el recordset de datos

        try
         {
            rs = x.sieuno_executediversosv2("select * from x1distribucion_insumos_entradas_catalogo("+opbus+",'"+tbusca+"',"+variables_global.getalmacen()+") as (idreg integer,iddocu character varying(12),statusdocu smallint,claveper character varying(45),docante character varying(12),docsig character varying(12),fechadoc date,fechaentrega date,fechavenci date,impuesto numeric,impuesto2 numeric,descuentoto numeric,descuentofinan numeric,idprovee character varying(12),obser character varying(80),usuario character varying(20),clasif smallint,almacen smallint,statusdescrip character varying(15),descripprovee character varying(60),canarticulo numeric,importe numeric,descripalmacen character varying(30));",variables_global.getconexiongral());
            while (rs.next())
                {
                this.jtf_almacen.setText(rs.getString ("descripalmacen"));
                this.jtf_folio.setText(rs.getString ("iddocu"));
                this.jtf_status.setText(rs.getString ("statusdocu")+":"+rs.getString ("statusdescrip"));
                this.jtf_fecha.setText(this.fechaeuropea(rs.getString ("fechadoc"))+":"+DiaSemana(this.fechaeuropea(rs.getString ("fechadoc"))));
                this.jtf_impuesto.setText(rs.getString ("impuesto"));
                 if(rs.getString("fechaentrega") != null)
                        {
                           this.jtf_fechaenterado.setText(rs.getString("fechaentrega")+":"+DiaSemana(rs.getString ("fechaentrega")));
                        }

                 if(rs.getString("fechavenci") != null )
                        {
                           this.jtf_fecharecibido.setText(rs.getString ("fechavenci")+":"+this.DiaSemana(rs.getString("fechavenci")));
                        }
               this.jtf_proveedor.setText(rs.getString ("descripprovee"));
               this.jtf_totalpiezas.setText(miformat.format(rs.getFloat("canarticulo")));
               this.jtf_observaciones.setText(rs.getString ("obser"));
               if(rs.getInt("statusdocu")==1 )
                    {
                        this.jbtn_guardar.setVisible(true);
                    }

                }

        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }


}

private void imprimirr(int pag,float ptotal,String folio)
    {

     java.util.Date fechahoya=new Date();

     this.objimpresora=new com_distri_folios_imprimir();
     this.objimpresora.setOneItem_cadenas_a_imprimir("          Re-Impresion:"+this.fechaeuropea(fechahoya)+"  Hora"+fechahoya.getHours()+":"+fechahoya.getMinutes()+" Usuario:"+variables_global.getNombre());
     this.objimpresora.setOneItem_cadenas_a_imprimir("          S.I. "+"  Id-Rep:CI-01  Compra Insumos ");
     //this.objimpresora.setOneItem_cadenas_a_imprimir("Fecha:"+this.+"");
     this.objimpresora.setOneItem_cadenas_a_imprimir("          Fecha Documento:"+this.jtf_fecha.getText());
     this.objimpresora.setOneItem_cadenas_a_imprimir("          Folio:"+this.jtf_folio.getText()+"");
     this.objimpresora.setOneItem_cadenas_a_imprimir("          Status Documento:"+this.jtf_status.getText()+"");
     this.objimpresora.setOneItem_cadenas_a_imprimir("          Proveedor:"+this.jtf_proveedor.getText()+"");
     this.objimpresora.setOneItem_cadenas_a_imprimir("          Observaciones:"+this.jtf_observaciones.getText()+"");
     this.objimpresora.setOneItem_cadenas_a_imprimir("*");
      if((pag+1)>ptotal)
        {
            this.objimpresora.setOneItem_cadenas_a_imprimir("          Total Piezas: "+this.jtf_totalpiezas.getText());
     this.objimpresora.setOneItem_cadenas_a_imprimir("          Subtotal:$"+this.jtf_subtotal.getText());
     //this.objimpresora.setOneItem_cadenas_a_imprimir("          Descuento:$"+this.jtf_descimporte.getText());
     this.objimpresora.setOneItem_cadenas_a_imprimir("          Impuesto:$"+this.jtf_impuestoimporte.getText());
     this.objimpresora.setOneItem_cadenas_a_imprimir("          Total:$"+this.jtf_total.getText());
     //this.objimpresora.setOneItem_cadenas_a_imprimir("          Diferencia en costo$: "+this.jtf_diferencia.getText());
     //this.objimpresora.setOneItem_cadenas_a_imprimir("          Flete$: "+this.jtf_flete.getText());
        }

this.objimpresora.setOneItem_cadenas_a_imprimir("          Pagina: "+(pag+1)+" de"+ptotal);
     this.objimpresora.setOneItem_cadenas_a_imprimir("..");

     this.objimpresora.setOneItem_cadenas_a_imprimir("*");
     this.objimpresora.setObjeto_tabla(jtb_insumos);
     this.objimpresora.imprimir_all(14,pag);
    }
private String  fechaeuropea(Date fecha) {
       SimpleDateFormat formateadorestaeuropa = new SimpleDateFormat("dd-MM-yyyy");
       String cadenafecha="";
       cadenafecha= formateadorestaeuropa.format(fecha);
       return cadenafecha;
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jtf_fecha = new javax.swing.JTextField();
        jtf_fechaenterado = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jtf_fecharecibido = new javax.swing.JTextField();
        jtf_observaciones = new javax.swing.JTextField();
        jtf_almacen = new javax.swing.JTextField();
        jtf_folio = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jtf_status = new javax.swing.JTextField();
        jcb_verfotos = new javax.swing.JCheckBox();
        jckbx_surtircompleto = new javax.swing.JCheckBox();
        jLabel5 = new javax.swing.JLabel();
        jtf_proveedor = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jtf_impuesto = new javax.swing.JTextField();
        jpn_cuerpo = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtb_insumos = new javax.swing.JTable()
        //{
            //  public boolean isCellEditable(int rowIndex, int mColIndex) {
                //    if (mColIndex < 3)
                //  return false;
                //else
                //return true;
                //}
            //}
        ;
        jtf_totalpiezas = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jbtn_guardar = new javax.swing.JButton();
        jbtn_salir = new javax.swing.JButton();
        jbtn_helpayudame = new javax.swing.JButton();
        jbtn_imprimir = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        jtf_subtotal = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jtf_impuestoimporte = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jtf_total = new javax.swing.JTextField();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jmni_salir = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jmni_escape = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sie_invdis.Sie_invdisApp.class).getContext().getResourceMap(insumos_entradas_detalle.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel1.border.title"))); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jtf_fecha.setEditable(false);
        jtf_fecha.setName("jtf_fecha"); // NOI18N

        jtf_fechaenterado.setEditable(false);
        jtf_fechaenterado.setName("jtf_fechaenterado"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jtf_fecharecibido.setEditable(false);
        jtf_fecharecibido.setName("jtf_fecharecibido"); // NOI18N

        jtf_observaciones.setEditable(false);
        jtf_observaciones.setName("jtf_observaciones"); // NOI18N

        jtf_almacen.setEditable(false);
        jtf_almacen.setName("jtf_almacen"); // NOI18N

        jtf_folio.setEditable(false);
        jtf_folio.setName("jtf_folio"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jtf_status.setEditable(false);
        jtf_status.setName("jtf_status"); // NOI18N

        jcb_verfotos.setText(resourceMap.getString("jcb_verfotos.text")); // NOI18N
        jcb_verfotos.setToolTipText(resourceMap.getString("jcb_verfotos.toolTipText")); // NOI18N
        jcb_verfotos.setName("jcb_verfotos"); // NOI18N
        jcb_verfotos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcb_verfotosActionPerformed(evt);
            }
        });

        jckbx_surtircompleto.setText(resourceMap.getString("jckbx_surtircompleto.text")); // NOI18N
        jckbx_surtircompleto.setName("jckbx_surtircompleto"); // NOI18N
        jckbx_surtircompleto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jckbx_surtircompletoActionPerformed(evt);
            }
        });

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jtf_proveedor.setEditable(false);
        jtf_proveedor.setName("jtf_proveedor"); // NOI18N

        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        jtf_impuesto.setEditable(false);
        jtf_impuesto.setText(resourceMap.getString("jtf_impuesto.text")); // NOI18N
        jtf_impuesto.setName("jtf_impuesto"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtf_status, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtf_folio, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtf_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtf_fecha, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jtf_fechaenterado, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel7)
                                .addGap(18, 18, 18)
                                .addComponent(jtf_fecharecibido, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel13)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jtf_impuesto))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jtf_almacen, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel4)
                                .addGap(13, 13, 13)
                                .addComponent(jtf_observaciones, javax.swing.GroupLayout.PREFERRED_SIZE, 346, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jcb_verfotos)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jckbx_surtircompleto)))
                .addContainerGap(16, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jtf_status, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(jtf_folio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(jtf_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jtf_fecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtf_fechaenterado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(jtf_fecharecibido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel13)
                    .addComponent(jtf_impuesto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jLabel4)
                    .addComponent(jtf_almacen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtf_observaciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jcb_verfotos)
                    .addComponent(jckbx_surtircompleto)))
        );

        jpn_cuerpo.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jpn_cuerpo.border.title"))); // NOI18N
        jpn_cuerpo.setName("jpn_cuerpo"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jtb_insumos.setModel(this.jtable_modelo);
        jtb_insumos.setName("jtb_insumos"); // NOI18N
        jScrollPane1.setViewportView(jtb_insumos);

        javax.swing.GroupLayout jpn_cuerpoLayout = new javax.swing.GroupLayout(jpn_cuerpo);
        jpn_cuerpo.setLayout(jpn_cuerpoLayout);
        jpn_cuerpoLayout.setHorizontalGroup(
            jpn_cuerpoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 704, Short.MAX_VALUE)
        );
        jpn_cuerpoLayout.setVerticalGroup(
            jpn_cuerpoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE)
        );

        jtf_totalpiezas.setEditable(false);
        jtf_totalpiezas.setName("jtf_totalpiezas"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel2.setName("jPanel2"); // NOI18N

        jbtn_guardar.setIcon(resourceMap.getIcon("jbtn_guardar.icon")); // NOI18N
        jbtn_guardar.setText(resourceMap.getString("jbtn_guardar.text")); // NOI18N
        jbtn_guardar.setName("jbtn_guardar"); // NOI18N
        jbtn_guardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_guardarActionPerformed(evt);
            }
        });

        jbtn_salir.setIcon(resourceMap.getIcon("jbtn_salir.icon")); // NOI18N
        jbtn_salir.setText(resourceMap.getString("jbtn_salir.text")); // NOI18N
        jbtn_salir.setName("jbtn_salir"); // NOI18N
        jbtn_salir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_salirActionPerformed(evt);
            }
        });

        jbtn_helpayudame.setIcon(resourceMap.getIcon("jbtn_helpayudame.icon")); // NOI18N
        jbtn_helpayudame.setText(resourceMap.getString("jbtn_helpayudame.text")); // NOI18N
        jbtn_helpayudame.setName("jbtn_helpayudame"); // NOI18N
        jbtn_helpayudame.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_helpayudameActionPerformed(evt);
            }
        });

        jbtn_imprimir.setIcon(resourceMap.getIcon("jbtn_imprimir.icon")); // NOI18N
        jbtn_imprimir.setText(resourceMap.getString("jbtn_imprimir.text")); // NOI18N
        jbtn_imprimir.setName("jbtn_imprimir"); // NOI18N
        jbtn_imprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_imprimirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(136, 136, 136)
                .addComponent(jbtn_imprimir)
                .addGap(44, 44, 44)
                .addComponent(jbtn_salir)
                .addGap(110, 110, 110)
                .addComponent(jbtn_helpayudame)
                .addContainerGap(177, Short.MAX_VALUE))
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jbtn_guardar)
                    .addContainerGap(597, Short.MAX_VALUE)))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jbtn_salir)
                .addComponent(jbtn_helpayudame)
                .addComponent(jbtn_imprimir))
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGap(2, 2, 2)
                    .addComponent(jbtn_guardar)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jtf_subtotal.setEditable(false);
        jtf_subtotal.setName("jtf_subtotal"); // NOI18N

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        jtf_impuestoimporte.setEditable(false);
        jtf_impuestoimporte.setName("jtf_impuestoimporte"); // NOI18N

        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        jtf_total.setEditable(false);
        jtf_total.setName("jtf_total"); // NOI18N

        jMenuBar1.setName("jMenuBar1"); // NOI18N

        jMenu1.setText(resourceMap.getString("jMenu1.text")); // NOI18N
        jMenu1.setName("jMenu1"); // NOI18N

        jmni_salir.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.ALT_MASK));
        jmni_salir.setIcon(resourceMap.getIcon("jmni_salir.icon")); // NOI18N
        jmni_salir.setText(resourceMap.getString("jmni_salir.text")); // NOI18N
        jmni_salir.setName("jmni_salir"); // NOI18N
        jmni_salir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmni_salirActionPerformed(evt);
            }
        });
        jMenu1.add(jmni_salir);

        jMenuBar1.add(jMenu1);

        jMenu2.setText(resourceMap.getString("jMenu2.text")); // NOI18N
        jMenu2.setName("jMenu2"); // NOI18N

        jmni_escape.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0));
        jmni_escape.setText(resourceMap.getString("jmni_escape.text")); // NOI18N
        jmni_escape.setName("jmni_escape"); // NOI18N
        jmni_escape.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmni_escapeActionPerformed(evt);
            }
        });
        jMenu2.add(jmni_escape);

        jMenuBar1.add(jMenu2);

        jMenu3.setText(resourceMap.getString("jMenu3.text")); // NOI18N
        jMenu3.setName("jMenu3"); // NOI18N
        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jpn_cuerpo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(121, 121, 121)
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtf_totalpiezas, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(31, 31, 31)
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtf_subtotal, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtf_impuestoimporte, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtf_total, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jpn_cuerpo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(4, 4, 4)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jtf_totalpiezas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(jtf_subtotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(jtf_impuestoimporte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(jtf_total, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(43, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jmni_salirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmni_salirActionPerformed
        // TODO add your handling code here:
 if(JOptionPane.showConfirmDialog(null, "Realmente Desea Salir?")==0)
        {
            this.dispose();
        }
    }//GEN-LAST:event_jmni_salirActionPerformed

    private void jcb_verfotosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcb_verfotosActionPerformed
        // TODO add your handling code here:
        if(this.jcb_verfotos.isSelected()==true) {
            //this.verfotosestereporte();
        } else {
            //this.quitarfotosestereporte();
        }
}//GEN-LAST:event_jcb_verfotosActionPerformed

    private void jckbx_surtircompletoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jckbx_surtircompletoActionPerformed
        // TODO add your handling code here:
        if(this.jckbx_surtircompleto.isSelected()==true) {
            // this.surtirtodo();
        }
}//GEN-LAST:event_jckbx_surtircompletoActionPerformed

    private void jbtn_guardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_guardarActionPerformed
        // TODO add your handling code here:
        // TODO add your handling code here:

        ResultSet rs = null;
        float cantidad=0;
        int nobjetotabla=this.jtb_insumos.getRowCount();
        int fi=0,controlfolio=0;

        String cadenafilas="{'", arreglo_articulos[]=null;
        JPasswordField pwd = new JPasswordField(10);
        //this.quitarfotosestereporte();
        //lanso la confirmacion de password
        int action = JOptionPane.showConfirmDialog(null, pwd,"Contraseña:(Use Tab p/moverse o Mause)",JOptionPane.OK_CANCEL_OPTION);
        if(action < 0) {
            JOptionPane.showMessageDialog(null,"No se realiza Proceso, Gracias");
        } else {
            //comparo si la contraseña es apropiada
            if(variables_global.getPassword().equals(String.valueOf(pwd.getPassword()))) {//inicia trabajo para actualizar diferencias


                for(fi=0;fi<nobjetotabla;fi++) {

                    try{
                        cantidad = Float.valueOf(this.jtb_insumos.getValueAt(fi, 3).toString()).floatValue();
                    }catch (NumberFormatException nfe) {
                        cantidad=0;
                    }
                    // System.out.println("cachar error"+cadenafilas);
                    if (cantidad > 0) {
                        cadenafilas+=""+this.jtb_insumos.getValueAt(fi, 3).toString()+":"+this.jtb_insumos.getValueAt(fi, 0).toString()+":"+this.jtb_insumos.getValueAt(fi, 4)+""+"\n";
                    }



                }//fin del for

                //System.out.println(s);
                //arreglo_articulos=cadenafilas.split(":");

                if(JOptionPane.showConfirmDialog(null, "Documento sera Guardado. Estan correcto sus Datos?")==0) {

                    //           this.quitardescripcion();
                    java.util.Vector arreglodearticulos=this.jtable_modelo.getDataVector();

                    String articulos_papostgresql=arreglodearticulos.toString();
                    articulos_papostgresql=articulos_papostgresql.replace('[','{');
                    articulos_papostgresql=articulos_papostgresql.replace(']','}');
                    articulos_papostgresql=articulos_papostgresql.replace("null",".");


                    String texto="select * from x1distribucion_insumos_entradas_recepcionar('"+this.jtf_folio.getText().toString()+"','"+articulos_papostgresql+"')";
                    System.out.println(texto);
                    rs=x.sieuno_executediversosv2(texto,variables_global.getconexiongral());
                    try {
                        while (rs.next()) {
                            controlfolio=rs.getInt(1);
                            if (rs.getInt(1) > 0) {
                                JOptionPane.showMessageDialog(null,"Requisicion Correcta, Gracias", "Sistema Integral(Requisicion Insumos) : Confirmacion",1);
                                //                      this.imprimir(1,1,controlfolio);

                            } else {
                                JOptionPane.showMessageDialog(null," Error Verifique sus Cantidades", "Sistema Integral(requisicion Insumos) : Error",1);
                            }
                        }

                    } catch(Exception e) {
                        System.out.println(e.getMessage());
                        JOptionPane.showMessageDialog(null," Recepcion Incorrecta ", "Sistema Integral(Requisicion Insumos) : Error",1);
                    }


                    //this.btn_guardar.setVisible(false);
                }//fin del if qu confirmo guardar diferencia

            } else {
                JOptionPane.showMessageDialog(null,"por Favor teclee su contraseña coreectamente, verifique mayusculas en teclado");
            }

        }
    }//GEN-LAST:event_jbtn_guardarActionPerformed

    private void jbtn_salirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_salirActionPerformed

        // TODO add your handling code here:
        //
        //x.cierraConexion();
        this.dispose();
}//GEN-LAST:event_jbtn_salirActionPerformed

    private void jbtn_helpayudameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_helpayudameActionPerformed
        // TODO add your handling code here:
        this.ayuda();
}//GEN-LAST:event_jbtn_helpayudameActionPerformed

    private void jbtn_imprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_imprimirActionPerformed
        // TODO add your handling code here:
 float filas = this.jtable_modelo.getRowCount() ;
        float paginas = filas /50;
        int ni=0;
        for(ni=0;ni<paginas;ni++)
             {
                this.imprimirr(ni, paginas,this.jtf_folio.getText());
            }
}//GEN-LAST:event_jbtn_imprimirActionPerformed

    private void jmni_escapeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmni_escapeActionPerformed
        // TODO add your handling code here:
        this.jmni_salirActionPerformed(evt);
    }//GEN-LAST:event_jmni_escapeActionPerformed

       private  void ayuda()
            {
                String punto1="1.-Detalle de Recepcion de Mercancia, cada opcion se autodescribe brevemente\n";
                String punto2="  2.- Cada Boton tiene Una letra Resaltada el cual indica su metodo abreviado uselo si desea mayor rapides ( ejemplo Alt+a tendra ayuda automaticamente)\n";
                String punto3="  3.- la opcion guardar esta activada para Recepcionar este documento Incluyendo Diferencias si no ingresa diferencias, el sistema guardara el documento como correcto\n";
                JOptionPane.showMessageDialog(null,punto1+punto2+punto3, "Sistema Integral(Detalle Recepcion) : Ayuda",1);
            }
 void LimpiarJTable()
 {
     //limpiar la tabla
    while(jtable_modelo.getRowCount()>0)jtable_modelo.removeRow(0);
 }

  private String DiaSemana(String fe) {
         String dia = "";
       java.util.Date fecha=null;
         try
            {
             fecha = formateador.parse(fe);

           }
        catch (ParseException e)
            {
            //Error, la cadena de texto no se puede convertir en fecha.
            }
        Calendar cal= Calendar.getInstance();
        cal.setTime(fecha);
        //ojo para establecer o recetear cada parte de la fecha por separado
        //cal.set(Calendar.YEAR, fecha.getYear());
        //cal.set(Calendar.MONTH, fecha.getMonth());
        //cal.set(Calendar.DAY_OF_MONTH, fecha.getDay());
        int diaInt = cal.get(Calendar.DAY_OF_WEEK);
        switch (diaInt) {
            case 1:
                dia = "Domingo";
                break;
            case 2:
                dia = "Lunes";
                break;
            case 3:
                dia = "Martes";
                break;
            case 4:
                dia = "Miercoles";
                break;
            case 5:
                dia = "Jueves";
                break;
            case 6:
                dia = "Viernes";
                break;
            case 7:
                dia = "Sabado";
                break;

        }
        return dia;
    }

  private String  fechaeuropea(String fecha) {
         //resibe cadena de fecha en formato americano yyyy-MM-dd
       java.util.Date fechaestaeuropa=null;
       SimpleDateFormat formateadorestaeuropa = new SimpleDateFormat("dd-MM-yyyy");
       String cadenafecha="";
        try
         {
          fechaestaeuropa = formateadoresta.parse(fecha);
         }
        catch (ParseException e)
          {
             //Error, la cadena de texto no se puede convertir en fecha.
          }
       cadenafecha= formateadorestaeuropa.format(fechaestaeuropa);
       return cadenafecha;
    }


    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                insumos_entradas_detalle dialog = new insumos_entradas_detalle(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbtn_guardar;
    private javax.swing.JButton jbtn_helpayudame;
    private javax.swing.JButton jbtn_imprimir;
    private javax.swing.JButton jbtn_salir;
    private javax.swing.JCheckBox jcb_verfotos;
    private javax.swing.JCheckBox jckbx_surtircompleto;
    private javax.swing.JMenuItem jmni_escape;
    private javax.swing.JMenuItem jmni_salir;
    private javax.swing.JPanel jpn_cuerpo;
    private javax.swing.JTable jtb_insumos;
    private javax.swing.JTextField jtf_almacen;
    private javax.swing.JTextField jtf_fecha;
    private javax.swing.JTextField jtf_fechaenterado;
    private javax.swing.JTextField jtf_fecharecibido;
    private javax.swing.JTextField jtf_folio;
    private javax.swing.JTextField jtf_impuesto;
    private javax.swing.JTextField jtf_impuestoimporte;
    private javax.swing.JTextField jtf_observaciones;
    private javax.swing.JTextField jtf_proveedor;
    private javax.swing.JTextField jtf_status;
    private javax.swing.JTextField jtf_subtotal;
    private javax.swing.JTextField jtf_total;
    private javax.swing.JTextField jtf_totalpiezas;
    // End of variables declaration//GEN-END:variables
private com_distri_folios_imprimir objimpresora;
}
